package com.alpha.crm;





import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import com.alpha.crm.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
//import android.widget.Toast;
import android.widget.Toast;

public class SingleMenuItemActivity  extends Activity {
	Button btn;
	EditText txtf, txtf2, txtf3;
	// XML node keys
	static final String KEY_NAME = "Name";
	static final String KEY_ID = "GID";
	static final String KEY_DESC = "Code";
	
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.single_list_item);
        
        // getting intent data
        Intent in = getIntent();
       // TextView tv;
        
        // Get XML values from previous intent
        String name = in.getStringExtra(KEY_NAME);
        final String gid = in.getStringExtra(KEY_ID);
        final String description = in.getStringExtra(KEY_DESC);
       // final String content = txtf.getText().toString();
        // Displaying all values on the screen
        TextView lblName = (TextView) findViewById(R.id.name_label);
        TextView lblCost = (TextView) findViewById(R.id.cost_label);
        TextView lblDesc = (TextView) findViewById(R.id.description_label);
      // tv = (TextView) findViewById(R.id.textView1);
        final EditText txtf = (EditText)findViewById(R.id.editText1);
        final EditText txtf2 = (EditText)findViewById(R.id.editText2);
        final EditText txtf3 = (EditText)findViewById(R.id.editText3);
        
        lblName.setText(name);
        lblCost.setText(gid);
        lblDesc.setText(description);
        //lblDesc.setText(description);
        //invisible gid
        lblCost.setVisibility(View.GONE);
        
        
        
        
        
        btn = (Button)findViewById(R.id.button1);
        
        
        btn.setOnClickListener(new View.OnClickListener()
        {
        	
        	
        	
            public void onClick(View v)
            {
            	
            	//"       <Code>"+description+"</Code>"+   "       <ReferredPersonGID></ReferredPersonGID>"
            	      // "       <fTableField1Code>2</fTableField1Code>" +    	
            	TextView tv ;
            	tv = (TextView) findViewById(R.id.textView1);
            	//tv2 = (TextView) findViewById(R.id.textView2);
            	
            	String format =
            			"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            			"<EBSDataset xmlns=\"http://tempuri.org/EBSDataset.xsd\">" +
            			"	<Customer>" +
            			"		<GID>"+gid+"</GID>" +
            			"		<LegalType>0</LegalType>" +
            			"		<VATStatus>0</VATStatus>" +
            			"		<CreateNewPerson>false</CreateNewPerson>" +
            			"       <StringField1>"+txtf2.getText().toString()+"</StringField1>" +
            			"       <DateField1>"+txtf3.getText().toString()+"</DateField1>" +
            			"       <NumericField1>"+txtf.getText().toString()+"</NumericField1>" +
            			"       <FlagField1>true</FlagField1>" +
            			"	</Customer>" +
            			"</EBSDataset>";
            	
            	
            	
            	SoapObject Request = new SoapObject (Question.NAMESPACE,Question.OPERATION_NAME);
    	        Request.addProperty("strCommand", "create_update_customer");
    	        Request.addProperty("strCommandParameters", format);
    	        
    	        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    	        soapEnvelope.dotNet = true;
    	        soapEnvelope.setOutputSoapObject(Request);
    	        
    	        try {
    	            HttpTransportSE androidHttpTransport = new HttpTransportSE(Question.URL);
    	           
    	            //this is the actual part that will call the webservice
    	            androidHttpTransport.call(Question.SOAP_ACTION, soapEnvelope);
    	           
    	            // Get the SoapResult from the envelope body.
    	           // SoapObject result = (SoapObject)soapEnvelope.bodyIn;
    	            tv.setText("Send Successful!");
    	           // tv2.setText("XML : " + format);
    	            Toast.makeText(SingleMenuItemActivity.this, "Send Successful!", Toast.LENGTH_LONG).show();
    	        
    	        } catch (Exception e) {
    		    	  tv.setText("error: " + e);
    		            e.printStackTrace();
    		      }
            }
        });
	}
}
        
	


            
        
        
        
		
    	
        
        
        
        
        
    

